#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;
int n, c;
int a[15][15];
int vis[15][15];
int tag;
int _count;
int num[15];
int dir[6][2] = {{-1, 0}, {-1, -1}, {0, -1}, {0, 1}, {1, 0}, {1, 1}};
void dfs(int x, int y, int term)
{

    for (int i = 0; i < 6; i++)
    {
        int xx = x + dir[i][0];
        int yy = y + dir[i][1];
        if (xx < 0 || yy < 0 || xx > n - 1 || yy > n - 1 || yy > xx)
            continue;
        if (a[xx][yy] != term && a[xx][yy] != 0)
            continue;
        if (a[xx][yy] == 0)
            tag = 1;
        if (vis[xx][yy])
            continue;
        vis[xx][yy] = 1;
        if (a[xx][yy] == term)
            _count++;
        dfs(xx, yy, term);
    }
}
int sove()
{
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= i; j++)
        {

            if (a[i][j] != 0 && vis[i][j] == 0)
            {
                vis[i][j] = 1;
                tag = 0;
                _count = 1;
                dfs(i, j, a[i][j]);
                if (tag == 0 && a[i][j] != c)
                    sum += _count;
                if (tag == 0 && a[i][j] == c)
                    sum -= _count;
            }
        }
    }
    return sum;
}

int main()
{
    int ans;
    while (scanf("%d%d", &n, &c) != EOF)
    {
        if (n == 0 && c == 0)
            break;
        ans = -9999999;
        memset(vis, 0, sizeof(vis));
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <= i; j++)
            {
                scanf("%d", &a[i][j]);
                num[a[i][j]]++;
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <= i; j++)
            {
                if (a[i][j] == 0)
                {
                    a[i][j] = c;

                    num[c]++;

                    memset(vis, 0, sizeof(vis));
                    int tmp = sove();
                    if (ans < tmp)
                        ans = tmp;
                    a[i][j] = 0;
                    num[c]--;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}